package com.xiaoma.thread.exceptionhandler;

import java.util.concurrent.ThreadFactory;

public class HandlerThreadFactory implements ThreadFactory {
    @Override
    public Thread newThread(Runnable r) {
        System.out.println(this+"create new thread");
        Thread t = new Thread(r);
        System.out.println("create"+t);
        t.setUncaughtExceptionHandler(new MyUncaughtExceptionhandler());//设置我们自定义的异常处理
        //Thread.setDefaultUncaughtExceptionHandler();也可使用此方法设置默认的处理器
        System.out.println("eh="+t.getUncaughtExceptionHandler());
        return t;
    }
}
